#include "TextureManager.h"

#include "TextureBMP.h"
#include "TexturePNG.h"

const std::wstring FILE_EXTENTION_BMP = L"bmp";

ITexture* TextureManager::LoadTexture(const std::wstring& path)
{
	ITexture* texture = NULL;
	if( !(texture = TexturePNG::Create(path)) )
		return NULL;
		
	//else if(texture = TextureBMP::Create(path))
	//	return texture;

	GLuint	textureId = 0;
	GLint	alignment;

	if(texture->GetTexels())
	{
		/* Generate texture */
		glGenTextures(1, texture->GetId());
		glBindTexture(GL_TEXTURE_2D, *texture->GetId());

		/* Setup some parameters for texture filters */
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

		glTexImage2D(GL_TEXTURE_2D, 0, texture->GetInternalFormat(), texture->GetWidth(), texture->GetHeight(), 0, texture->GetFormat(), GL_UNSIGNED_BYTE, texture->GetTexels());

		textureId = *texture->GetId();
	}

	return texture;
}